package com.brillilab.service.core.lab.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.brillilab.dao.mapper.lab.LabJoinAuditMapper;
import com.brillilab.domain.enums.lab.LabJoinAuditStateEnum;
import com.brillilab.domain.po.lab.LabJoinAudit;
import com.brillilab.service.core.lab.ILabJoinAuditService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 加入实验室审核表 服务实现类
 * </p>
 *
 * @author zlb
 * @since 2019-09-24
 */
@Service
public class LabJoinAuditServiceImpl extends ServiceImpl<LabJoinAuditMapper, LabJoinAudit> implements ILabJoinAuditService {

    @Resource
    private LabJoinAuditMapper labJoinAuditMapper;

    @Override
    public LabJoinAudit insert(LabJoinAudit labJoinAudit) {
        Integer b = labJoinAuditMapper.insert(labJoinAudit);
        return b == 1 ? labJoinAudit : null;
    }

    @Override
    public boolean updateById(LabJoinAudit labJoinAudit) {
        Integer b = labJoinAuditMapper.updateById(labJoinAudit);
        return b == 1 ? true : false;
    }

    @Override
    public LabJoinAudit selectById(Long id) {
        return labJoinAuditMapper.selectById(id);
    }

    @Override
    public List<LabJoinAudit> selectListByState(Integer state) {
        LambdaQueryWrapper<LabJoinAudit> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(LabJoinAudit::getState, state);
        return labJoinAuditMapper.selectList(wrapper);
    }

    @Override
    public LabJoinAudit selectOne(Long userId,Long labId,LabJoinAuditStateEnum stateEnum) {
        return labJoinAuditMapper.selectOne(
                new LambdaQueryWrapper<LabJoinAudit>()
                        .eq(LabJoinAudit::getUserId,userId)
                        .eq(LabJoinAudit::getLabId,labId)
                        .eq(LabJoinAudit::getState,stateEnum.getValue()));
    }

    @Override
    public List<LabJoinAudit> selectList(Long userId,LabJoinAuditStateEnum stateEnum) {
        return labJoinAuditMapper.selectList(
                new LambdaQueryWrapper<LabJoinAudit>()
                        .eq(LabJoinAudit::getUserId,userId)
                        .eq(LabJoinAudit::getState,stateEnum.getValue()));
    }
}
